<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form
      size="mini"
      ref="form"
      :model="form"
      label-position="top"
      class="myform"
    >
      <div>
        <!-- <el-form-item label="供应商" class="myform-item">
          <el-input
            v-model="form.factory_name"
            placeholder="请输入供应商"
            clearable
            @keyup.enter.native="onSearch"
          ></el-input>
        </el-form-item> -->
        <el-form-item label="供应商/供应商品名/成分" class="myform-item">
          <el-input
            v-model="form.title"
            placeholder="请输入供应商/供应商品名/成分"
            clearable
            @keyup.enter.native="onSearch"
          ></el-input>
        </el-form-item>
        <el-form-item label="面料类型" class="myform-item">
          <el-select v-model="form.types" placeholder="请选择">
            <el-option
              v-for="item in mlList"
              :key="item.id"
              :label="item.title"
              :value="item.title"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item style="margin-top: 38px">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
      <div  v-if="qxobj.save">
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onEdit()" icon="el-icon-plus"
            >新建</el-button
          >
        </el-form-item>
      </div>
    </el-form>
    <el-table
      :data="tableData"
      style="width: 100%"
      border
      size="mini"
      :height="browserHeight - 260"
    >
      <el-table-column fixed label="状态" align="center" prop="status">
        <template slot-scope="{ row }">
          <div :style="{color:row.status==0?'red':'#67C23A'}">
            {{ row.status==0?"已禁用":"已启用" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        fixed
        label="供应商"
        align="center"
        prop="factory_name"
      ></el-table-column>
      <el-table-column
        label="供应商品名"
        align="center"
        prop="product_name"
        fixed
      >
      </el-table-column>
      <el-table-column label="面料类型" align="center" prop="types" fixed>
      </el-table-column>
      <el-table-column label="成分" align="center" prop="ingredients">
      </el-table-column>
      <el-table-column
        label="染后布重"
        align="center"
        prop="fabric_weight_after_dyeing"
      >
      </el-table-column>
      <el-table-column
        label="染后全幅"
        align="center"
        prop="full_width_after_dyeing"
      >
      </el-table-column>
      <el-table-column
        label="染后有效门幅"
        align="center"
        prop="effective_door_width_after_dyeing"
      >
      </el-table-column>
      <el-table-column label="大货价格" align="center" prop="big_price">
      </el-table-column>
      <el-table-column
        label="大货报价时间"
        align="center"
        prop="big_price_time"
      >
      </el-table-column>
      <el-table-column
        label="供应商品名编号"
        align="center"
        prop="product_code"
      ></el-table-column>
      <el-table-column
        label="条形码"
        align="center"
        prop="bar_code"
      ></el-table-column>
      <el-table-column
        label="出米数"
        align="center"
        prop="meter_output"
      ></el-table-column>
      <el-table-column
        label="面料照片"
        align="center"
        prop="fabric_pic"
        width="200"
      >
        <template slot-scope="{ row }">
          <div
            class="fileimage pointer"
            v-for="(item, index) in row.fabric_pic"
            :key="index"
            @click="onFile(item)"
          >
            <img src="../../../assets/images/list.png" fit="fill" />
            {{ item | fileFilters }}
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="色卡照片"
        align="center"
        prop="color_pic"
        width="200"
      >
        <template slot-scope="{ row }">
          <div
            class="fileimage pointer"
            v-for="(item, index) in row.color_pic"
            :key="index"
            @click="onFile(item)"
          >
            <img src="../../../assets/images/list.png" fit="fill" />
            {{ item | fileFilters }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="挂钩标签"
        align="center"
        prop="hook_label"
        width="200"
      >
        <template slot-scope="{ row }">
          <div
            class="fileimage pointer"
            v-for="(item, index) in row.hook_label"
            :key="index"
            @click="onFile(item)"
          >
            <img src="../../../assets/images/list.png" fit="fill" />
            {{ item | fileFilters }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="使用部位" align="center" prop="application_site">
      </el-table-column>
      <el-table-column
        label="基本组织"
        align="center"
        prop="basic_organization"
      >
      </el-table-column>

      <el-table-column
        label="染后密度"
        align="center"
        prop="density_after_dyeing"
      ></el-table-column>

      <el-table-column label="工艺风险" align="center" prop="process_risk">
      </el-table-column>
      <el-table-column
        label="面料库呈现形式"
        align="center"
        prop="fabric_library_presentation"
      >
      </el-table-column>
      <!-- <el-table-column
        label="供应商备货情况"
        align="center"
        prop="supplier_stock_up"
      >
      </el-table-column> -->
      <el-table-column
        label="印染工艺"
        align="center"
        prop="printing_and_dyeing_process"
      >
      </el-table-column>
      <el-table-column
        label="后工艺适用性"
        align="center"
        prop="post_process_practicability"
      >
      </el-table-column>
      <!-- <el-table-column
        label="坯布密度"
        align="center"
        prop="embryo_cloth_density"
      >
      </el-table-column> -->
      <el-table-column
        label="经纱规格"
        align="center"
        prop="light_yarn_specification"
      >
      </el-table-column>
      <!-- <el-table-column
        label="坯布经纱用纱量"
        align="center"
        prop="yarn_quantity_of_embryo_cloth_yarn"
      >
      </el-table-column> -->
      <el-table-column
        label="纬纱规格"
        align="center"
        prop="weft_specification"
      >
      </el-table-column>
      <!-- <el-table-column
        label="坯布纬纱用纱量"
        align="center"
        prop="weft_yarn_quantity_of_embryo_cloth"
      >
      </el-table-column> -->
      <!-- <el-table-column
        label="坯布织造机型"
        align="center"
        prop="embryo_fabric_weaving_machine"
      >
      </el-table-column> -->
      <!-- <el-table-column
        label="坯布核成本"
        align="center"
        prop="embryo_core_cost"
      >
      </el-table-column> -->
      <!-- <el-table-column label="染缸" align="center" prop="dye_vat">
      </el-table-column> -->
      <!-- <el-table-column
        label="色布核成本"
        align="center"
        prop="color_cloth_core_cost"
      >
      </el-table-column> -->
      <!-- <el-table-column
        label="成本核价时间"
        align="center"
        prop="cost_pricing_time"
      >
      </el-table-column> -->
      <el-table-column
        label="工艺单照片"
        align="center"
        prop="process_sheet_photo"
        width="200"
      >
        <template slot-scope="{ row }">
          <div
            class="fileimage pointer"
            v-for="(item, index) in row.process_sheet_photo"
            :key="index"
            @click="onFile(item)"
          >
            <img src="../../../assets/images/list.png" fit="fill" />
            {{ item | fileFilters }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="实际大货面料评估"
        align="center"
        prop="actual_bulk_fabric_evaluation"
      >
      </el-table-column>
      <el-table-column
        label="供应商联系方式"
        align="center"
        prop="supplier_contact_information"
      >
      </el-table-column>
      <!-- <el-table-column label="曾经使用部位" align="center" prop="used_parts">
      </el-table-column> -->
      <el-table-column
        label="摆放位置信息"
        align="center"
        prop="placement_position"
      >
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="100" v-if="qxobj.save">
        <template slot-scope="{ row }">
          <el-button type="text" @click="onEdit(row.id)">编辑</el-button>
          <!-- <el-button type="text" style="color: red" @click="onDelete(row.id)"
            >删除</el-button
          > -->
          <el-button
            type="text"
            style="color: red"
            v-if="row.status == 1"
            @click="onIs(row.id, 0)"
            >禁用</el-button
          >
          <el-button
            type="text"
            style="color: #67c23a"
            v-if="row.status == 0"
            @click="onIs(row.id, 1)"
            >启用</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminPricingGetFabricList"
    />
  </div>
</template>

<script>
import {
  postAdminPricingGetFabricList,
  postHomeCodeGetFactory,
  postAdminPricingSaveFabric,
  postAdminPricingDelFabric,
  postAdminProductionDisablEOrtherProduct,
  postAdminProductionGettypeslist
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      qxobj:{},
      loading: false,
      dialogVisible: false, //创建
      browserHeight: "",
      factoryList: [],
      mlList: [],
      supplier_id: "",
      form: {
        title: "",
        // factory_name: "",
        types: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
    };
  },
  filters: {
    fileFilters(value) {
      return value.substring(value.length - 15);
    },
  },
  activated() {
    this.browserHeight =
      window.innerHeight ||
      document.documentElement.clientHeight ||
      document.body.clientHeight;
    let form = this.form;
    this.qxobj = JSON.parse(this.$route.query.qxobj)
    this.postHomeCodeGetFactory();
    this.postAdminPricingGetFabricList(form);
    this.postAdminProductionGettypeslist();
  },
  methods: {
    // 面料类型
    async postAdminProductionGettypeslist() {
      let obj = {
        page:1,
        size:1000
      }
      let res = await postAdminProductionGettypeslist(obj);
      this.mlList = res.data;
    },
    // 加工厂列表
    postHomeCodeGetFactory() {
      let obj = {
        type: 8,
        page: 1,
        size: 1000,
      };
      postHomeCodeGetFactory(obj).then((res) => {
        this.factoryList = res.data;
      });
    },
    // 新建弹窗
    onCreate() {
      this.supplier_id = "";
      this.dialogVisible = true;
    },
    // 新建
    async onSubmit() {
      let { form, supplier_id } = this;
      let obj = {
        supplier_id: supplier_id,
      };
      try {
        await postAdminPricingSaveFabric(obj);
        this.postAdminPricingGetFabricList(form);
      } catch (error) {}
    },

    // 查看
    onEdit(id) {
      if (!id) {
        this.$router.push({
          name: "OperationalDepartmentFabricEdit",
        });
      } else {
        this.$router.push({
          name: "OperationalDepartmentFabricEdit",
          query: { id },
        });
      }
    },
    async onIs(id, status) {
      let obj = {
        id: id,
        is_disable: status,
      };
      this.$confirm(`确定${status == 0 ? "禁用" : "启用"}`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          await postAdminProductionDisablEOrtherProduct(obj);
          let form = this.form;
          this.postAdminPricingGetFabricList(form);
        })
        .catch(() => {});
    },
    // 删除
    onDelete(id) {
      let obj = {
        id,
      };
      let { form } = this;
      this.$confirm("确定删除此面料信息?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminPricingDelFabric(obj).then((res) => {
            this.postAdminPricingGetFabricList(form);
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    // 采购列表
    async postAdminPricingGetFabricList(data) {
      this.loading = true;
      this.form = data;
      postAdminPricingGetFabricList(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminPricingGetFabricList(this.form);
    },
    // 文件跳转
    onFile(e) {
      window.open(e);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.fileimage {
  display: flex;
  align-items: center;
  > img {
    width: 16px;
    height: 16px;
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
